/*
 * General abstract class for templating Items
 */

package item;

import java.io.Serializable;
import java.util.Comparator;

public abstract class Item implements Serializable{
	
	private static final long serialVersionUID = -81546951463646259L;
	
	public String name; //name of the object
	public int cost; //cost of the object in credits
	public int condition; //condition of the object
	public int level; //how good the object is
	public int weight; //the mass of the object
	public String spritePath; //what the item looks like, where the sprite iss
	
	//creates an Item object
	
	protected Item(int cost, int condition, int level, int weight) {
		this.name = "";
		this.cost = cost;
		this.condition = condition;
		this.level = level;
		this.weight = weight;
		this.spritePath = "assets\\images\\";
	}//end of constructor with parameters Item
	
	public String toString() {
		return name;
	}
	
	//calculates credits gained through selling
	
	public int sell() {
		return cost / 2;
	}//end of method sell
	
	//calculates scrap gained through salvaging
	
	public int salvage() {
		return cost / 10;
	}//end of method salvage
	
	//decrements condition
	
	public void decay() {
		condition--;
	}//end of method decay;

	//creates a comparator using cost
	
	public static Comparator<Item> getCostComparator() {
		return new Comparator<Item>() {
				public int compare(Item one, Item two) {
					return two.cost - one.cost;
				}//end of method compare
		}; //end of anonymous inner class
	}//end of method getCostComparator
	
	//creates a comparator using condition
	
	public static Comparator<Item> getConditionComparator() {
		return new Comparator<Item>() {
				public int compare(Item one, Item two) {
					return two.condition - one.condition;
				}//end of method compare
		};//end of anonymous inner class 
	}//end of method getCostComparator
	
	//creates a comparator using weight
	
	public static Comparator<Item> getWeightComparator() {
		return new Comparator<Item>() {
			public int compare(Item one, Item two) {
				return two.weight - one.weight;
			}//end of method compare
		};//end of anonymous inner class 
	}//end of method getCostComparator
	
	//creates a comparator using level
	
	public static Comparator<Item> getLevelComparator() {
		return new Comparator<Item>() {
			public int compare(Item one, Item two) {
				return two.level - one.level;
			}//end of method compare
		};//end of anonymous inner class 
	}//end of method getCostComparator

}//end of class Item
